<%@ page import="java.sql.SQLException" %>
<%@ page import="java.util.List" %>
<%@ page import="DAO.JavaBean.CustomerBean" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: 28064
  Date: 2022/3/22
  Time: 19:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:useBean id="customer" class="DAO.JavaDAO.CustomerDAO" scope="session" />
<%--<jsp:setProperty name="customer" property="*"/>--%>
<html>
<head>
    <title>show Customer</title>
    <style>
        table {
            font-family: "FiraCode Nerd Font", 'serif';
            width: auto;
            height: fit-content;
            text-align: center;
            align-content: center;
        }
        td {text-align: center;}
    </style>
</head>
<body>
<form action="../action" method="post" name="action">
<table border="1" >
    <tr>
        <th scope="col">custName</th>
        <th scope="col">email</th>
        <th scope="col">phone</th>
        <th scope="col">operation</th>
    </tr>
    <%
//        CustomerDAO customer=new CustomerDAO();
        try {
//            for ( CustomerBean cust:customer.search("")) {
        ResultSet rs= customer.result();
        while (rs.next()){
//            System.out.println(cust);
    %>
    <tr>
        <td ><%=rs.getString(1)%></td>
<%--        <input type="text" value="<%=rs.getString(1)%>" name="custName" hidden>--%>
        <td><%=rs.getString(2)%></td>
<%--        <input type="text" value="<%=rs.getString(2)%>" name="email" hidden>--%>
        <td><%=rs.getString(3)%></td>
<%--        <input type="text" value="<%=rs.getString(3)%>" name="phone" hidden>--%>
        <td><input type="button" value="修改" name="update" onclick="location.href='updatepage.jsp?name=<%=rs.getString(1)%>&email=<%=rs.getString(2)%>&phone=<%=rs.getString(3)%>'">
<%--                   onclick="windows.location.href='../action?operation=update&id=<%=cust.getCustName()%>'" >--%>
            &emsp;&emsp;
            <input type="button" value="删除" name="delete" onclick="location.href='../action?id=<%=rs.getString(1)%>'"></td>
<%--        尝试使用javascript进行判断--%>
<%--        <td><input type="button" value="修改" name="update" onclick="up(this)" >&emsp;&emsp;<input type="button" value="删除" name="delete" onclick="del(this);"></td>--%>
    </tr>
    <%}} catch (SQLException ignored) {
        }
    %>
</table>
</form>
<script type="application/javascript">
    function del(val) {
        const flag = confirm("if you want to delete this info");
        //alter提示，confirm布尔，prompt信息填写
        if (flag){
            console.log("删除数据",val)
            // href
            //post name

            // windows.location.href("../action")
        }
        else {
            console.log("undo")
        }
    }
    function up(val) {
        var info=prompt("please input which you want to update");
        var arr=info.split(" ");
        console.log(arr)
        if (arr.length==2){
            //post email change
            //post phone change
            console.log("update two info")
        }
        else{
            if (arr[0].includes('@')){
                console.log("this is a email")
            }
            else{
                console.log("this is a phone number")
            }
        }
    }
</script>
</body>
</html>
